package org.example.myleet.p485;

public class Solution {
    /**
     * 2 ms
     * 双指针法，遇到0的时候记录一次最长连续1的个数，并s重置左右指针到下一位1
     */
    public int findMaxConsecutiveOnes(int[] nums) {
        int maxCount = 0, l = 0, r = 0, n = nums.length;
        for (int i=r; i<n; i++) {
            if (nums[r] == 1) {
                ++r;
            } else {
                maxCount = Math.max(r - l, maxCount);
                l = r + 1;
                r = r + 1;
            }
        }
        maxCount = Math.max(r - l, maxCount);
        return maxCount;
    }
}
